package com.sos.core.game.requests
{
	import com.sos.core.DataObject;

	public class GameRequestError extends DataObject
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------
		
		// JSON properties names
		protected static const		JSON_PROPERTY_CODE:String               = "code";
		protected static const		JSON_PROPERTY_MESSAGE:String            = "message";
		
		// Default values
		public static const         DEFAULT_CODE:int						= 0;
		public static const         DEFAULT_MESSAGE:String					= "";
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _code:int;
		private var _message:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------
		
		public function GameRequestError(data:Object = null)
		{
			// Clear data
			clear();
			// If data is provided, initializes data object
			if (data != null) load(data);
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------

		public function get code():int
		{
			return _code;
		}

		public function get message():String
		{
			return _message;
		}

		// -------------------------------------------------------------------------------
		// PRIVATE METHODS
		// -------------------------------------------------------------------------------
		
		// DataObject implementation
		
		override protected function validate(data:Object):void
		{
			if (!data.hasOwnProperty(JSON_PROPERTY_CODE))		throwLoadMissingPropError(JSON_PROPERTY_CODE);
			if (!data.hasOwnProperty(JSON_PROPERTY_MESSAGE))	throwLoadMissingPropError(JSON_PROPERTY_MESSAGE);
		}
		
		override protected function fill(data:Object):void
		{
			_code = int(data[JSON_PROPERTY_CODE]);
			_message = data[JSON_PROPERTY_MESSAGE];
		}

		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		override public function clear():void
		{
			_code 		= DEFAULT_CODE;
			_message 	= DEFAULT_MESSAGE;			
		}
		

	}
}